//
//  LGReportDetailHeaderView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/5/25.
//

#import "LGReportDetailHeaderView.h"

@interface LGReportDetailHeaderView()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIButton *numberBtn;

@end

@implementation LGReportDetailHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.titleLabel.text = LGNSString(dataDic[@"report_name"]);
    if([dataDic.allKeys containsObject:@"report_date"]){
        self.timeLabel.text = LGNSString(dataDic[@"report_date"]);
    }else if([dataDic.allKeys containsObject:@"hospitalized_time"]){
        NSString *enter = LGNSString(dataDic[@"hospitalized_time"]);
        enter = (enter.length>=10)?[enter substringToIndex:10]:enter;
        
        NSString *leave = LGNSString(dataDic[@"leave_time"]);
        leave = (leave.length>=10)?[leave substringToIndex:10]:leave;
        self.timeLabel.text = [NSString stringWithFormat:@"%@ ~ %@",enter,leave];
    }else if([dataDic.allKeys containsObject:@"visit_date"]){
        self.timeLabel.text = LGNSString(dataDic[@"visit_date"]);
    }else if([dataDic.allKeys containsObject:@"operation_date"]){
        self.timeLabel.text = LGNSString(dataDic[@"operation_date"]);
    }
    self.nameLabel.text = LGNSString(dataDic[@"patientname"]);
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@",dataDic[@"sex"],dataDic[@"age"]];
    [self.numberBtn setTitle:LGNSString(dataDic[@"hospital_bano"]) forState:UIControlStateNormal];
}


-(void)createSubView{
    self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.timeLabel];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.numberBtn];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(14));
        make.left.equalTo(self.baseView).offset(viewPix(16));
        make.right.equalTo(self.baseView).offset(-viewPix(16));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(10));
        make.left.right.equalTo(self.titleLabel);
    }];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(16));
        make.bottom.equalTo(self.baseView).offset(-viewPix(16));
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(5);
        make.centerY.equalTo(self.iconView);
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(10));
        make.centerY.equalTo(self.iconView);
        make.width.equalTo(@(70));
        make.height.equalTo(@(22));
    }];
    [self.numberBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(24));
        make.centerY.equalTo(self.iconView);
        make.width.equalTo(@(120));
        make.height.equalTo(@(22));
    }];
}


-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.frame = CGRectMake(viewPix(16), viewPix(16), Screen_W-viewPix(32), viewPix(112));
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}


-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _titleLabel;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"报告详情-姓名"]];
    }
    return _iconView;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#2E9AFC" textFont:LGFont(14) textAlignment:NSTextAlignmentCenter lines:1];
        _ageLabel.backgroundColor = [UIColor colorWithString:@"#EAF4FF"];
        _ageLabel.cornerRidus = 11;
    }
    return _ageLabel;
}

-(UIButton *)numberBtn{
    if(!_numberBtn){
        _numberBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(16) textColor:@"#666666" imageName:@"报告详情-编号"];
        _numberBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _numberBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    }
    return _numberBtn;
}
@end
